package com.oracle.oa.dao.impl;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.oracle.oa.dao.ReadCommonMessageDao;

public class ReadCommonMessageDaoImpl extends BaseDaoImpl implements ReadCommonMessageDao {

	/**
	 * 批量删除某个messageid的用户已读的消息
	 */
	
	public int deleteBymessageid(Object messageid) {
		int count=0;
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		//构建hql语句
		String hql="delete from Readcommonmessage as rcm where rcm.message.messageid=:messageid";
		count = session.createQuery(hql)
				.setParameter("messageid", messageid)
				.executeUpdate();
		
		session.close();
		return count;
	}

	/**
	 * 删除用户已读消息，根据messageid和userinfo
	 */
	
	public int deleteBymesAndUser(Object messageid, Object userid) {
		int count = 0;
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		//构建hql语句
		String hql="delete from Readcommonmessage as rcm where rcm.message.messageid=:messageid and rcm.userinfo.userid=:userid";
		count = session.createQuery(hql)
				.setParameter("messageid", messageid)
				.setParameter("userid", userid)
				.executeUpdate();
		session.close();
		return count;
	}


}
